<template>
    <div>
        <el-table :data="data" style="width:100%" border>
                <el-table-column v-for="item in column"  :key="item.label" :prop="item.prop" :label="item.label"  :sortable='item.sortable'   >
                    <template  slot-scope="scope">
                        <div v-if="item.type == 'time'">
                             {{scope.row[item.prop]|formatDate(item.timetype)|timeDate()}}
                        </div>
                        <div v-else-if="item.type == 'tag'">
                            <el-tag>{{scope.row[item.prop]|categorysTitles()}}</el-tag>
                        </div>
                        <div v-else-if="item.type == 'sorttext'">
                            {{item.soltcontent.replace(/sort/,scope.row[item.prop])}}
                        </div>
                        <div v-else>
                            {{scope.row[item.prop]}}
                        </div>
                    </template>
                </el-table-column>
                <slot></slot>
            </el-table>
    </div>
</template>

<script>
export default {
    data(){
        return{

        }
    },
    props:{
        data:{
            type:Array,
            defualt:() =>{
                return []
            },
        },
        column:{
            type:Array,
            defualt:() =>{
                return []
            },
        },
    },
    filters: {
     //   时间戳转换时间格式
      formatDate: function (value) {
        let date = new Date(value);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? ('0' + MM) : MM;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let m = date.getMinutes();
        m = m < 10 ? ('0' + m) : m;
        let s = date.getSeconds();
        s = s < 10 ? ('0' + s) : s;
        return y+'-'+ MM + '-' + d + '-' + h + ':' + m +':'+ s
      },
      categorysTitles:function(value){
          return !value?'全部类目':value
      },
      timeDate:function(value){
        return value=='NaN-NaN-NaN-NaN:NaN:NaN'?'无':value
      },
      gmtStarts:function(value,time){//当前时间小于本地时间就显示已过期否则就现在下架正常
         return time<new Date().getTime()?'已过期':value==0?'下架':'正常'
      }
  },
}
</script>